<template>
    <el-card>
        <div slot="header">新建项目</div>
        <project_info_form v-model="form" @submit="submit" :message="message" :loading="loading"/>
    </el-card>
</template>

<script>
    import Project_info_form from "../component/project_info_form";

    export default {
        components: {
            Project_info_form,
        },
        data() {
            return {
                loading: false,
                message: {show: false, type: null, content: ''},
                form: {},
            };
        },
        methods: {
            submit() {
                this.loading = true;
                this.$http.post('/api/project', this.form).then(res => {
                    this.message = {show: true, type: 'success', content: '创建项目成功，请等待跳转'};
                    setTimeout(() => {
                        this.$router.push('/project/' + res.data.id);
                    }, 1500);
                }).catch(err => {
                    this.message = {show: true, type: 'error', content: err.response.data};
                    this.loading = false;
                });
            },
        },
    }
</script>

<style scoped>
    .flex > * {
        width: 50%;
    }
</style>